/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.virtual.model;

import offset.nodes.server.html.model.NodeSubstituter;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import offset.nodes.Constants;
import offset.nodes.client.virtual.model.jcr.SimpleNode;
import offset.nodes.server.html.model.HtmlSubstituter;
import offset.nodes.server.html.model.HttpContext;

public class VirtualSubstituter extends HtmlSubstituter implements NodeSubstituter {
    Session session;
    String host;
    int port;

    public VirtualSubstituter(Session session) {
        super(session);
    }

    @Override
    public Node substitute(Node node, Node parent) throws RepositoryException {
        if (!node.isNodeType(Constants.TYPE_HTML_DIV) || !node.hasProperty(Constants.JCR_DATA))
            return node;
        SimpleNode result;
        if (node instanceof SimpleNode)
            result = (SimpleNode) node;
        else
            result = new SimpleNode(node, SimpleNode.FORMAT_USER, SimpleNode.COPYMODE_DO_NOT_COPY_CHILDREN);
        result.setProperty(Constants.JCR_DATA, substituteHyperlinks(result.getProperty(Constants.JCR_DATA).getString()));
        return result;
    }

 }
